Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scripts to generate certificate and add it to the macOS Keychain and iOS Keychain #44

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

subdan
Copy link
Collaborator

@subdan subdan commented Nov 27, 2021

Scripts/generate-self-signed-certificate.sh — generates self signed certificate (root-ca.pem) using Scripts/cert.config config file.
Scripts/extract-certificate-from-keychain.sh — extracts certificate from the local macOS Keychain
Scripts/add-certificate-to-system-keychain.sh — adds a certificate to the local macOS Keychain
Scripts/add-certificate-to-ios-keychain.sh — adds a certificate to the booted iOS Simulator

Closes #41

openssl genrsa -aes256 -passout pass:"$password" -out key.pem 2048

# Generate the self-signed certificate and private key
openssl req -x509 -new -nodes -passin pass:"$password" -config cert.config -key key.pem -sha256 -extensions v3_ca -days 365 -out root-ca.pem
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not used "$CERT_FILE" with -config

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

C=RU
L=RU
O=Catbird
CN=Catbird
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here you probably need to specify the host?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but we do not have website.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to http://localhost


# Generate the self-signed certificate and private key
openssl req -x509 -new -nodes -passin pass:"$password" -config cert.config -key key.pem -sha256 -extensions v3_ca -days 365 -out root-ca.pem

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For Vaport, the key is needed in the Key format .key

openssl rsa -outform der -in key.pem -out cert.key -passin pass:"$password"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.


# Get path to the local keychain and trim whitespaces and quotation marks symbol
LOGIN_KEYCHAIN="$(security login-keychain | sed 's/[[:space:]]*"//g')"
security add-trusted-cert -k $LOGIN_KEYCHAIN root-ca.pem
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I need to add to the system Keychain ?

sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain root-ca.pem

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems, no.

@Alexander-Ignition
Copy link
Collaborator

I checked like this

import NIOSSL

// ...

try app.http.server.configuration.tlsConfiguration = .makeServerConfiguration(
    certificateChain: NIOSSLCertificate.fromPEMFile("cert.pem").map { .certificate($0) },
    privateKey: .file("cert.key")
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Self-signed certificate for HTTPS Proxy
2 participants